<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="{yun:}$config.sy_weburl{/yun}/js/jquery-1.8.0.min.js?v={yun:}$config.cachecode{/yun}"></script>
<script src="js/admin_public.js?v={yun:}$config.cachecode{/yun}" language="javascript"></script>  
<link href="{yun:}$config.sy_weburl{/yun}/js/layui/css/layui.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet">
<script src="{yun:}$config.sy_weburl{/yun}/js/layui/layui.js?v={yun:}$config.cachecode{/yun}" language="javascript"></script>
<script src="{yun:}$config.sy_weburl{/yun}/js/layui/phpyun_layer.js?v={yun:}$config.cachecode{/yun}"></script>
<title>后台管理</title>
</head>
<script type="text/javascript">
layui.use(['layer', 'form'], function(){
    var layer = layui.layer
    ,form = layui.form
    ,$ = layui.$;
});
var weburl="{yun:}$config.sy_weburl{/yun}";
function save_industry(){ 
	var name  =$("input[name='add_name']").val();
	var pytoken =$("#pytoken").val();
	var keyid =$("#add_keyid_val").val();
	var key  =$("input[name='add_key']").val();
	var type  =$("#add_type_val").val();
	var url  =$("input[name='add_url']").val();
	var sort  =$("input[name='add_sort']").val();
	var navid = $("#navid").val(); 
	if($.trim(name)==''){
		parent.layer.msg('菜单名称不能为空！', 2, 8);return false;
	}
	if(keyid !='0' && type=='click' && type==''){
		parent.layer.msg('点击事件，菜单关键字不得为空！', 2, 8);return false;
	}
	if(keyid !='0' && type=='view' && url==''){
		parent.layer.msg('链接事件，菜单链接不得为空！', 2, 8);return false;
	}
	
	$.post("index.php?m=wx&c=edit",{name:name,keyid:keyid,type:type,key:key,url:url,sort:sort,navid:navid,pytoken:pytoken},function(msg){
		if(msg==1){ 
			parent.layer.msg('请按要求填写信息！', 2, 8);return false;
		}else if(msg==2){
			parent.layer.msg('相同名称或关键字已存在！', 2, 8);return false;
		}else if(msg==3){
			parent.layer.msg('操作成功！', 2,9,function(){location=location ;});return false;
		}else if(msg==4){
			parent.layer.msg('操作成功！', 2,8,function(){location=location ;});return false;
		}
	}); 
}  

function editnav(id,name,keyid,keyname,key,type,url,sort){	
	$("#navid").val(id);
	$("input[name='add_name']").val(name);	
	$("input[name='add_sort']").val(sort);
	
	//$("#add_keyid_val").next().find("dd[lay-value='"+keyid+"']").click();
	$("#add_keyid_val").val(keyid);
	//$("#add_type_val").next().find("dd[lay-value='"+type+"']").click();
	$("#add_type_val").val(type);
	layui.form.render('select');
	$("input[name='add_url']").val(url);
	$("input[name='add_key']").val(key);
	
	add_class('修改微信菜单','400','400','#houtai_div','');
}

function addnav(){	
	
	clearnav();
	add_class('新增微信菜单','400','400','#houtai_div','');
	
}


function clearnav(){  
	$("#navid").val('');
	$("input[name='add_name']").val('');
	$("#add_keyid_val").val(0);
	$("input[name='add_key']").val('');
	$("#add_type_val").val('');
	$("input[name='add_url']").val('');
	$("input[name='add_sort']").val(''); 
	layui.form.render('select');
} 
function navsync(){
	parent.layer.confirm('确定要同步菜单至微信服务器？',function(){
		parent.layer.load('执行中，请稍候...',0);
		var pytoken=$("#pytoken").val();	
		$.get("index.php?m=wx&c=creat&pytoken="+pytoken,function(msg){
      parent.layer.closeAll('loading');
			if(msg==1){
				parent.layer.msg('微信菜单创建成功！', 2, 9);return false;
			}else{
				parent.layer.msg('微信菜单创建失败！', 2,8);return false;
			}
		}); 
	});
}
</script>
<link href="images/reset.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<link href="images/system.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" />
<link href="images/table_form.css?v={yun:}$config.cachecode{/yun}" rel="stylesheet" type="text/css" /> 

<body class="body_ifm">
<div class="infoboxp"> 
<div class="admin_new_tip">
<a href="javascript:;" class="admin_new_tip_close"></a>
<a href="javascript:;" class="admin_new_tip_open" style="display:none;"></a>
<div class="admin_new_tit"><i class="admin_new_tit_icon"></i>操作提示</div>
<div class="admin_new_tip_list_cont">
<div class="admin_new_tip_list">微信菜单功能可以实现添加、修改和删除等操作，管理员也可以设置个性化网站或名称。设置后，点击“同步微信菜单”轻松同步到微信公众号中！</div>
</div>
</div>
<div class="clear"></div>
<div style="height:10px;"></div>


<div class="infoboxp_top">
<span class="admin_title_span">微信菜单管理</span>
<a  href="javascript:void(0)" onClick="addnav();" class="admin_infoboxp_tj">增加微信菜单</a>
<a  href="javascript:void(0);"  onclick="navsync();" class="admin_infoboxp_tj">同步微信菜单</a>
</div>
<div class="clear"></div>
<div class="table-list">
  <div class="admin_table_border">
  <iframe id="supportiframe"  name="supportiframe" onload="returnmessage('supportiframe');" style="display:none"></iframe>
<form action="index.php?m=wx&c=delnav" method="post" target="supportiframe" id='myform'>  
<table width="100%">
	<thead>
	<tr class="admin_table_top">
   		<th width="50"><label for="chkall"> <input type="checkbox" id='chkAll' onclick='CheckAll(this.form)' /></label></th>
		<th align="left">菜单标题<span class="clickup">(点击修改)</span></th>
        <th align="left">菜单类型</th>
         <th align="left">菜单关键字</th>
        <th align="left">菜单链接</th>
        <th align="left">排序</th>
		<th width="180" class="admin_table_th_bg">操作</th>
	</tr>
	</thead>
	<tbody>
	{yun:}foreach from=$navlist item=v {/yun}
	<tr align="left">
  	    <td width="50" align='center'><input type="checkbox" value="{yun:}$v.id{/yun}" name='del[]' onclick='unselectall()' rel="del_chk" /></td>
		<td class="ud"><span onClick="checkname('{yun:}$v.id{/yun}');" id="name{yun:}$v.id{/yun}" style="cursor:pointer;">{yun:}$v.name{/yun}</span> <input class="input-text hidden" type="text" id="inputname{yun:}$v.id{/yun}"value="{yun:}$v.name{/yun}" onBlur="subname('{yun:}$v.id{/yun}','index.php?m=wx&c=ajax');"/>
		<img class="" style="padding-left:5px;cursor:pointer;" title="" src="images/xg.png" onClick="checkname('{yun:}$v.id{/yun}');"/>
		</td>
		<td class="ud">{yun:}$v.type{/yun}</td>
        <td>{yun:}$v.key{/yun}</td>
		<td>{yun:}$v.url{/yun}</td>
        <td><span onClick="checksort('{yun:}$v.id{/yun}');" id="sort{yun:}$v.id{/yun}" style="cursor:pointer;">{yun:}$v.sort{/yun}</span>
        <input class="input-text hidden" type="text" id="input{yun:}$v.id{/yun}" size="10" value="{yun:}$v.sort{/yun}" onBlur="subsort('{yun:}$v.id{/yun}','index.php?m=wx&c=ajax');"/>
		<img class="" style="padding-left:5px;cursor:pointer;" title="" src="images/xg.png" onClick="checksort('{yun:}$v.id{/yun}');"/>
		</td>
		<td class="ud" style="text-align:center">
         <a href="javascript:editnav('{yun:}$v.id{/yun}','{yun:}$v.name{/yun}','{yun:}$v.keyid{/yun}','一级菜单','{yun:}$v.key{/yun}','{yun:}$v.type{/yun}','{yun:}$v.url{/yun}','{yun:}$v.sort{/yun}');" class="admin_new_c_bth">修改</a>
        <A href="javascript:void(0)" onClick="layer_del('确定要删除？', 'index.php?m=wx&c=delnav&delid={yun:}$v.id{/yun}');"class="admin_new_c_bth admin_new_c_bth_sc">删除</a></td>
	</tr> 
    {yun:}if $v.list{/yun}
    {yun:}foreach from=$v.list item=vv {/yun} 
	<tr align="left">
  	    <td width="50" align='center'><input type="checkbox" value="{yun:}$vv.id{/yun}" name='del[]' onclick='unselectall()' rel="del_chk" /></td>
		<td class="ud">----<span onClick="checkname('{yun:}$vv.id{/yun}');" id="name{yun:}$vv.id{/yun}" style="cursor:pointer;">{yun:}$vv.name{/yun}</span> <input class="input-text hidden" type="text" id="inputname{yun:}$vv.id{/yun}"value="{yun:}$vv.name{/yun}" onBlur="subname('{yun:}$vv.id{/yun}','index.php?m=wx&c=ajax');"/>
		<img class="" style="padding-left:5px;cursor:pointer;" title="" src="images/xg.png" onClick="checkname('{yun:}$vv.id{/yun}');"/>
		</td>
		<td class="ud">{yun:}$vv.type{/yun}</td>
         <td>{yun:}$vv.key{/yun}</td>
		<td>{yun:}$vv.url{/yun}</td>
        <td><span onClick="checksort('{yun:}$vv.id{/yun}');" id="sort{yun:}$vv.id{/yun}" style="cursor:pointer;">{yun:}$vv.sort{/yun}</span>
        <input class="input-text hidden" type="text" id="input{yun:}$vv.id{/yun}" size="10" value="{yun:}$vv.sort{/yun}" onBlur="subsort('{yun:}$vv.id{/yun}','index.php?m=wx&c=ajax');"/>
		<img class="" style="padding-left:5px;cursor:pointer;" title="" src="images/xg.png" onClick="checksort('{yun:}$vv.id{/yun}');"/>
		</td>
		<td class="ud" style="text-align:center">
          <a href="javascript:editnav('{yun:}$vv.id{/yun}','{yun:}$vv.name{/yun}','{yun:}$vv.keyid{/yun}','{yun:}$v.name{/yun}','{yun:}$vv.key{/yun}','{yun:}$vv.type{/yun}','{yun:}$vv.url{/yun}','{yun:}$vv.sort{/yun}');" class="admin_new_c_bth">修改</a>
        <a href="javascript:void(0)" onClick="layer_del('确定要删除？', 'index.php?m=wx&c=delnav&delid={yun:}$vv.id{/yun}');"class="admin_new_c_bth admin_new_c_bth_sc">删除</a></td>
	</tr> 
	{yun:}/foreach{/yun} 
    {yun:}/if{/yun}
{yun:}/foreach{/yun}
    <tr>
	<input type="hidden" name="pytoken"  id='pytoken'value="{yun:}$pytoken{/yun}">
      <td colspan="2"><input class="admin_button"  type="button" name="delsub" value="删除所选"  onclick="return really('del[]')"/></td>
    </tr>
	</tbody>
</table>

</form>
</div>
</div>
</div>
<div id="houtai_div" style="  display:none;">
<div class="wx_mt10">
<form class="layui-form">
   <table cellspacing='1' cellpadding='1' class="admin_examine_table">
		<tbody> 
        	<tr class="ui_td_11" >
				<th width="110">菜单标题：</th>
                <td><input type="text" name="add_name" value="" class="admin_wx_text" /></td>
			</tr>
        <tr class="ui_td_11" >
				<th>菜单数组：</th>
                <td>
                <div class="layui-form-item">
                  <div class="layui-input-block">
                     <div class="layui-input-inline">
                       <select name="add_keyid" lay-filter="" id="add_keyid_val">
                      <option value="0">一级菜单</option>
                      {yun:}foreach from=$navlist item=v{/yun}
                      <option value="{yun:}$v.id{/yun}">{yun:}$v.name{/yun}</option>
                      {yun:}/foreach{/yun}
                    </select>
                     </div>
                   </div>
                </div>
                </td>
            </tr>
			<tr class="ui_td_11">
				<th>菜单类型：</th>
				<td>
                <div class="layui-form-item">
                  <div class="layui-input-block">
                     <div class="layui-input-inline">
                       <select name="add_type"  lay-filter="" id="add_type_val">
						<option value="">请选择</option>
						<option value="click">点击事件</option>
						<option value="view">链接事件</option>
                     
                    </select>
                     </div>
                   </div>
                </div>
                </td>
               
			</tr>
            <tr class="ui_td_11">
				<th>菜单关键字：</th>
                <td><input type="text" name="add_key" class="admin_wx_text" /></td>
			</tr>

            <tr class="ui_td_11">
				<th>菜单链接：</th>
                <td><input type="text" name="add_url" class="admin_wx_text" /></td>
			</tr>
			<tr class="ui_td_11" >
				<th>排序：</th>
                <td><input type="text" name="add_sort" size='5' class="admin_wx_text" onKeyUp="this.value=this.value.replace(/[^0-9]/g,'')"/></td>
			</tr>
			<tr class="ui_td_11 ">
				<td  class="ui_content_wrap" colspan='2'>
                <input type="hidden" name="navid" id="navid" value="">
                <input class="layui-btn layui-btn-normal" type="button" name="add" value=" 确认 " onClick="save_industry()" /></td>
			</tr> 
		</tbody>
	</table>
</form>
    </div>
</div>   
  </body>
</html>